<?php

$queryString       = $_GET['v'];  
$data              = explode ('/',$queryString);#print_r($data);
for ($i=0;$i<sizeof($data);$i+=2)
{  
    if (!is_numeric($data[$i]))
    {
        $_GET[ $data[$i] ] =  $data[$i + 1]; 
    }
} 



$grp  = $_GET['groupname'];
if (!isset($grp)) $grp = 'alt.binaries.lsm';
$sXml = "data/{$grp}.xml";


# LOAD XML FILE 
$XML = new DOMDocument(); 
$XML->load( $sXml ); 

$rootElement = $XML->documentElement;

// append subscribed groups
#echo $rootElement->tagName;
$my = GetSubscribedGroups();
foreach ($my as $group)
{ 
	$tmp = $XML->createElement ('group', $group);
	$rootElement->appendChild ($tmp); 
}
 

# START XSLT 
$xslt = new XSLTProcessor(); 
$XSL  = new DOMDocument(); 

$XSL->load( 'app.xsl', LIBXML_NOCDATA); 
$b = $xslt->importStylesheet( $XSL ); 
 


$xslt->setParameter('', 'pageindex', 2);

while (list ($key, $value) = each ($_GET))
{
	$xslt->setParameter('', $key, $value);
}


#PRINT 
print $xslt->transformToXML( $XML ); 



    function GetSubscribedGroups()
    {    
        $subdata = Topen ('data/subdata.txt');
        parse_str($subdata);
        sort ($my);
        return $my;
    }
	
	function Topen ($f)
	{
		$fp = fopen ($f, 'r');
		$fr = fread($fp, filesize($f));
		fclose ($fp);
		return $fr;
	}
?>
